package cn.com.bluemoon.daps.sync.vo.applypublish;

import io.swagger.annotations.ApiModelProperty;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;
import java.util.Collections;
import java.util.List;

/**
 * @author Jarod.Kong
 * @date 2021/7/30 10:12
 */
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
public class ApplyPublishResultVo implements Serializable {

    private static final long serialVersionUID = 1L;

    @ApiModelProperty("发布版本号")
    private String compareVersion;

    @ApiModelProperty("对比结果集")
    private List<ModelCompareVo> modelCompareVos;

    @ApiModelProperty("对比报告")
    private List<TableApplyPublishReportVo> reportVos;

    @ApiModelProperty("描述信息")
    private String message;

    @ApiModelProperty("申请发布是否成功 true成功 false失败")
    private Boolean applyPublish;

    public static ApplyPublishResultVo errorSandBox(String sqlExceptionMsg) {
        return ApplyPublishResultVo.builder().message("沙箱环境数据源创建失败，info：" + sqlExceptionMsg)
                .applyPublish(false).build();
    }

    /**
     * 生成语法失败结果
     *
     * @param reportVos 校验报告
     * @return this
     */
    public static ApplyPublishResultVo errorReport(List<TableApplyPublishReportVo> reportVos) {
        return ApplyPublishResultVo.builder().reportVos(reportVos)
                .message("模型表-建表语句语法错误")
                .applyPublish(false).build();
    }

    /**
     * 生成对比为空，失败结果
     *
     * @return this
     */
    public static ApplyPublishResultVo errorCompareResultEmpty() {
        return ApplyPublishResultVo.builder().modelCompareVos(Collections.emptyList())
                .message("模型版本对比，无变化，对比结果为空")
                .applyPublish(false).build();
    }

    /**
     * 生产对比成功结果
     * @param compareVersion 对比版本号
     * @param compareVos 结果集
     * @return this
     */
    public static ApplyPublishResultVo applyPublish(String compareVersion, List<ModelCompareVo> compareVos) {
        return ApplyPublishResultVo.builder().compareVersion(compareVersion).modelCompareVos(compareVos)
                .applyPublish(true).build();
    }

    public static ApplyPublishResultVo success() {
        return ApplyPublishResultVo.builder().applyPublish(true).build();
    }
}
